from globals import *
from menu import *
from world import *

class driver(DirectObject):

    MAIN_MENU = 0
    WORLD = 1
    #WIN_MENU = 2
    #LOST_MENU = 3
    
    def __init__(self):
        self.state = self.MAIN_MENU
        self.main_menu = menu()
        self.world = None
        
        taskMgr.add(self.update, "Main_Update")
        
        self.accept("escape", sys.exit)
        

    def update(self, task):
        #print "The state is...%s\n" % self.state
        if self.state==self.WORLD:
            #self.world.update(task)
            pass
                
        elif self.state == self.MAIN_MENU:
            self.main_menu.choose(task)
            if self.main_menu.start_game():
                self.main_menu.disable()
                self.state=self.WORLD
                if self.world!=None:
                    for ent in allEntities:
                        ent.die()
                    self.world.cur_check.die()
                self.world = world()
                #self.world.enable()
        
        #elif self.state==self.WIN_MENU:
        #   self.won_screen.update(task)
        #    if self.won_screen.return_menu():
        #        self.state=self.MAIN_MENU
        #        self.won_screen.disable()
        #        self.main_menu.enable()
                
        #elif self.state==self.LOST_MENU:
        #    self.lost_screen.update(task)
        #    if self.lost_screen.return_menu():
        #        self.state=self.MAIN_MENU
        #        self.lost_screen.disable()
        #        self.main_menu.enable()
                
        return Task.cont
